<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/common/commonCss.jsp"/>
<jsp:include page="/common/commonJs.jsp"/>


<link rel="stylesheet" type="text/css" href="${basePath}commonCss/css/global.css">
<link rel="stylesheet" type="text/css" href="${basePath}commonCss/css/layout.css">
<link rel="stylesheet" type="text/css" href="${basePath}commonCss/css/easyui.css">
<link rel="stylesheet" type="text/css" href="${basePath}commonCss/css/zTreeStyle.css">
<script src="${basePath}commonJs/jt_normal.js"></script>
<script src="${basePath}commonJs/jt_select.js"></script>
<script src="${basePath}commonJs/jquery.ztree.all.js"></script>
<title>嘉童游乐中心-单位设置</title>
<script type="text/javascript">
 function openUpdate(){
	 $('#updateCell').window('open');
 }
 $(document).ready(function(){
	 initParams();
	 
 });
 
//初始化参数
 function initParams() {
	$("#pageNo").val("1");
	$("#pageSize").val("8");
	var myform = $("#unitInfo");
 	var pagebean = new PageBean(myform);
 	pagebean.setTableId("showData");
 	pagebean.setFootId("foot");
 	pagebean.setCallback(showData);
 	setPagebeanObj(pagebean); //全局化pageBean对象
 	pagebean.doPage();  //执行分页
 }
 //展示数据
 function showData(result){
 	$(result).each(function(index,item){
 		var html="<tr>";
 		 html+="<td>"+(index+1)+"</td>";
 		 if(item.unitName.length>10){
 	 		 html+="<td pkPrdunitId="+item.pkPrdunitId+" class='lv'><a href='#'  onclick='forwardToUpdate(this);'>"+item.unitName.substring(0,10)+"...</a></td>";
 		 }else{
 	 		 html+="<td pkPrdunitId="+item.pkPrdunitId+" class='lv'><a href='#'  onclick='forwardToUpdate(this);'>"+item.unitName+"</a></td>";
 		 }
 		 if(item.floatFlag==1){
 			 html+="<td>是</td>";
 		 }else{
 			 html+="<td>否</td>";
 		 }
 		 if(item.comments==null||item.comments==""){
 	 		 html+="<td>无</td>";
 		 }else{
 			 if(item.comments.length>7){
 				html+="<td title="+item.comments+">"+item.comments.substring(0,7)+"...</td>";
 			 }else{
 				html+="<td>"+item.comments+"</td>";
 			 }

 		 }
 		 html+="<td pkPrdunitId="+item.pkPrdunitId+">";
         html+="<input type='button' class='btn_l' onclick='deleteUnit(this);' value='删除'  /></td></tr>";
 		$("#showData").find("tr:eq("+index+")").after(html);
 	});
 }
 //查询单位设置的信息
 function findUnitInfo(){
	 initParams();
 }
 //跳转到增加页面
 function forwardToAdd(){
	 //重置表单
	 $("#saveUnit")[0].reset();
	 $("#saveCell").window('open');
 }
 //保存单位设置信息
 function saveUnit(){
	 	
	 	var val=$("#unitName").val();
	 	if(val==""||$.trim(val)==""){
	 		alertInfo("单位名称不能为空");
	 		return;
	 	}
	 	val=$("input:[name='TfloatFlag']:checked").val();
	 	$('#floatFlag').val(val);
	 	
		$.ajax({
			url:"${basePath}scmInvocing/countUnit/saveUnit.shtml",
			data:$("#saveUnit").serialize(),
			dataType:"text",
			type:"post",
			async:false,
			error : function(XMLHttpRequest) {
	 				ajaxError(XMLHttpRequest);
	 		},
			success:function(result){
				$("#saveCell").window('close');
				initParams();
				alertInfo($common_create_success);
			}
		});
 }
 //删除单位信息
 function deleteUnit(obj){
	 	var pkPrdunitId=$(obj).parent().attr("pkPrdunitId");
	 	$.messager.confirm('温馨提示', '确定要执行删除操作吗?', function(isOk) {
			if (isOk) {
			$.ajax({
				url:"${basePath}scmInvocing/countUnit/updateUnit.shtml",
				data:{"pkPrdunitId":pkPrdunitId,"delFlag":"1"},
				dataType:"text",
				type:"post",
				async:false,
				error : function(XMLHttpRequest) {
  	 				ajaxError(XMLHttpRequest);
  	 			},
				success:function(result){
					initParams();
					alertInfo($common_delete_success);
				}
			});
		}
	 	});
 }
 //跳转到修改页面
 function forwardToUpdate(obj){
	 	var pkPrdunitId=$(obj).parent().attr("pkPrdunitId");
	 
	 	//请求数据
	 	$.ajax({
			url:"${basePath}scmInvocing/countUnit/findUnitInfo.shtml",
			data:{"pkPrdunitId":pkPrdunitId},
			dataType:"json",     
			type:"post",
			async:false,
			error : function(XMLHttpRequest) {
	 				ajaxError(XMLHttpRequest);
	 			},
			success:function(result){
					//json数据
					if(result.results!=null){
						var obj=result.results[0];
				/* 	$("#updateCell").html("");
					var html="<div class='editor_h1 fixed'><div class='editor fl'><form id='updateUnit'  method='post'>";
				     html+="<input type='hidden' name='floatFlag'  id='floatFlag'/>";
				     html+="<input type='hidden' name='pkPrdunitId' id='pkPrdunitId'/>";
				     html+="<ul><li><label>单位名称：</label> <input type='text' class='iput_t w200' name='unitName' id='unitName' value="+obj.unitName+"> <font style='color:#F00'>*</font></li>";
				     if(obj.floatFlag=='1'){
					     html+="<li><label>是否允许小数：</label>是<input type='radio' checked='checked' name='TfloatFlag' value='1'>&nbsp;否<input type='radio' name='TfloatFlag' value='0'></li>";
				     }else{
					     html+="<li><label>是否允许小数：</label>是<input type='radio' name='TfloatFlag' value='1'>&nbsp;否<input type='radio' name='TfloatFlag' value='0'  checked='checked'></li>";
				     }
				     html+="<li><label>备注：</label><textarea  rows='5' cols='35' name='comments' value="+obj.comments+"></textarea></li>";
				     html+="<li> <br/><br/><label>&nbsp;&nbsp;&nbsp;</label><input class='btn' type='button' value='修改' onclick='updateUnit();'> &nbsp;&nbsp;&nbsp; <input class='btn' type='button' value='取消' onclick='$('#updateCell').window('close')'></li>";
				     html+="</ul></form></div></div></div>";
				     $("#updateCell").html(html); */
				    var html='';
				    html+='<div class="editor_h1 fixed"><div class="editor fl"><form id="updateForUnit" type="post">';
				    html+='<input type="hidden" name="pkPrdunitId" id="updatePkPrdunitId" value='+obj.pkPrdunitId+'>';
				    html+='<input type="hidden" name="floatFlag" id="updateFloatFlag" value="">';
				    html+='<ul><li><label>单位名称：</label> <input type="text" class="iput_t w200"  name="unitName"   id="updateUnitName" value='+obj.unitName+' > <font style="color:#F00">*</font></li>';
				    if(obj.floatFlag=='1'){
				        html+='<li><label>是否允许小数：</label>是<input type="radio" checked="checked" name="updateFloatFlag" value="1">&nbsp;否<input type="radio" name="updateFloatFlag" value="0"></li>';
				    }else{
				        html+='<li><label>是否允许小数：</label>是<input type="radio" name="updateFloatFlag" value="1">&nbsp;否<input type="radio" name="updateFloatFlag" value="0" checked="checked" ></li>';

				    }
			        html+='<li><label class="vt">备注：</label><textarea class="w200 textare" value='+obj.comments+' name="comments">'+obj.comments+'</textarea></li>';
			        html+='<li> </br></br><label>&nbsp;&nbsp;&nbsp;</label><input class="btn" type="button" value="修改"  onclick="updateUnit();"> &nbsp;&nbsp;&nbsp; <input class="btn" type="button" value="取消" onclick="javascript:closeWindow();"></li></ul>';
			        html+='</form></div></div>';
					$("#TestWindow").html(html);
					}
			}
			
		});
		$("#TestWindow").window('open');

	 
 }
 function closeWindow(){
	 $("#TestWindow").window('close');
 }
 //修改单位设置信息
 function updateUnit(){
		var val=$("#updateUnitName").val();
	 	if(val==""||$.trim(val)==""){
	 		alertInfo("单位名称不允许为空!");
	 		return;
	 	}
	 	val=$("input:[name='updateFloatFlag']:checked").val();
	 	$('#updateFloatFlag').val(val);
	 	$.ajax({
			url:"${basePath}scmInvocing/countUnit/updateUnit.shtml",
			data:$("#updateForUnit").serialize(),
			dataType:"text",
			type:"post",
			async:false,
			error : function(XMLHttpRequest) {
	 				ajaxError(XMLHttpRequest);
	 			},
			success:function(result){
				$("#TestWindow").window('close');
				initParams();
				alertInfo($common_edit_success);
				
			}
		});

 }
</script>
</head>
<body class="bg">
<div class="content m_auto">
	<div class="content_l mt10">
    	<ul>
    		<shiro:hasPermission name="scmInvocing/productInfo/forwardToProductInfo.shtml">
    				  <li ><a href="${basePath}scmInvocing/productInfo/forwardToProductInfo.shtml"><i class="nav_icon_b"></i><br>商品信息</a></li>
    		</shiro:hasPermission>
    		 <shiro:hasPermission name="scmInvocing/countUnit/forwardToUnitInfo.shtml">
    		 		<li  class="content_hover"><a href="${basePath}scmInvocing/countUnit/forwardToUnitInfo.shtml"><i class="nav_icon_b"></i><br>单位设置</a></li>
    		 </shiro:hasPermission>
    		 <shiro:hasPermission name="scmInvocing/supplier/forwardToSupply.shtml">
    		 		   <li><a href="${basePath}scmInvocing/supplier/forwardToSupply.shtml"><i class="nav_icon_a"></i><br>供应商信息</a></li>
    		 </shiro:hasPermission>
    		  <shiro:hasPermission name="scmInvocing/priceManager/forwardToList.shtml">
    		 		  <li><a href="${basePath}scmInvocing/priceManager/forwardToList.shtml"><i class="nav_icon_f"></i><br>价格管理</a></li>
    		 </shiro:hasPermission>
    		   <shiro:hasPermission name="scmInvocing/scmPurOrder/findInvoPurOrder.shtml">
            	  <li><a href="${basePath}scmInvocing/scmPurOrder/findInvoPurOrder.shtml"><i class="nav_icon_b"></i><br>采购订单</a></li>
    		 </shiro:hasPermission>
    		   <shiro:hasPermission name="scmInvocing/scmPayForm/findInvoOrderPay.shtml">
           		   <li><a href="${basePath}scmInvocing/scmPayForm/findInvoOrderPay.shtml"><i class="nav_icon_b"></i><br>付款申请</a></li>
    		 </shiro:hasPermission>
  		 </ul>
    </div>
    <div class="content_r mt10">
    	<div class="p20">
    	<div class="file_single_dl f14 fixed">
    		<form action="${basePath}scmInvocing/countUnit/findUnitInfo.shtml" id="unitInfo">
    		<input type="hidden" name="pageNo" id="pageNo" value="1">
    		<input type="hidden" name="pageSize" id="pageSize" value="8">
    			<dl class="fixed" style="overflow:hidden">
            		<dd><label>单位名称：</label><input type="text" class="iput_t w200" name="unitName"></dd>
                
               		 <dd >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" class="btn ml10" value="查询" onclick="findUnitInfo();">
               		 	             <input class="btn ml10" type="button" value="新增" onclick="forwardToAdd();">
               		 </dd>
           		 </dl>
    		</form>
        </div>
       
        <div class="mt10">
          	<ul class="fixed" id="tab_conbox_a">
                <li class="p10 h450" style="margin-left:10px">
                	<table class="table" id="showData">
                    	<tr>
                        	<th>序号</th>
                            <th>单位名称</th>
                            <th>是否允许小数</th>
                            <th>备注</th>
                            <th>操作</th> 
                        </tr>
                    </table>
                    <!---翻页-->
                    <div class="page fr m10">
                    	<dd class="fr" id="foot">
                          
                      </dd>
                      
                    </div>
                    <!----->
                </li>
                </ul>
                </div>
        </div>
    </div>
</div>
 
<!-- save的弹出框-->
<div id="saveCell" class="easyui-window" title="新增单位" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:500px; height:300px;position:relative;">
	<div class="editor_h1 fixed">
      <div class="editor fl">
      	<form id="saveUnit"  method="post">
      		<input type="hidden" name="floatFlag"  id="floatFlag"/>
          <ul>
               <li><label>单位名称：</label> <input type="text" class="iput_t w200" value="" name="unitName" id="unitName"> <font style="color:#F00">*</font></li>
                <li><label>是否允许小数：</label>是<input type="radio" checked="checked" name="TfloatFlag" value="1">&nbsp;否<input type='radio' name="TfloatFlag" value="0"></li>
                <li><label>备注：</label><textarea  rows="5" cols="35" name="comments" ></textarea></li>
                
                 <li> <br/><br/><label>&nbsp;&nbsp;&nbsp;</label><input class="btn" type="button" value="保存" onclick="saveUnit();"> &nbsp;&nbsp;&nbsp; <input class="btn" type="button" value="取消" onclick="$('#saveCell').window('close')"></li>
           </ul>
           </form>
           
        </div>
    </div> 
</div>
<!-- update的弹出层 -->
	<!-- <div id="updateCell" class="easyui-window" title="修改单位" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:500px; height:300px;position:relative;">
	<div class="editor_h1 fixed">
      <div class="editor fl">
      	<form id="updateUnit"  method="post">
      		<input type="hidden" name="floatFlag"  id="floatFlag"/>
      		<input type="hidden" name="pkPrdunitId" id="pkPrdunitId"/>
          <ul>
               <li><label>单位名称：</label> <input type="text" class="iput_t w200" value="" name="unitName" id="unitName"> <font style="color:#F00">*</font></li>
                <li><label>是否允许小数：</label>是<input type="radio" checked="checked" name="TfloatFlag" value="1">&nbsp;否<input type='radio' name="TfloatFlag" value="0"></li>
                <li><label>备注：</label><textarea  rows="5" cols="35" name="comments" ></textarea></li>
                
                 <li> <br/><br/><label>&nbsp;&nbsp;&nbsp;</label><input class="btn" type="button" value="保存" onclick="updateUnit();"> &nbsp;&nbsp;&nbsp; <input class="btn" type="button" value="取消" onclick="$('#updateCell').window('close')"></li>
           </ul>
           </form>
            
    	
      
        </div>
    </div> 
</div> -->
<div id="TestWindow" class="easyui-window" title="修改单位" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:500px; height:300px;position:relative;">
	
</div>
</body>
</html>



